package forward.Module.Modules.Misc;

import forward.Module.Module;
import forward.Module.ModuleType;
import forward.Module.Modules.Move.NoSlow;
import forward.Util.BlockUtils;
import forward.Util.Helper;
import forward.api.EventHandler;
import forward.api.EventUpdate;
import forward.api.Events.World.EventPacketReceive;
import forward.api.Events.World.EventPacketSend;
import forward.api.Events.World.EventPreUpdate;
import forward.api.Value.Mode;
import forward.api.Value.Numbers;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C00PacketKeepAlive;
import net.minecraft.network.play.client.C03PacketPlayer;
import net.minecraft.potion.Potion;
import org.apache.commons.lang3.RandomUtils;

public class Regen extends Module{
    private int width;
    public Mode<Enum> mode = new Mode("Mode", "Mode", (Enum[])RegMode.values(), (Enum) RegMode.Old);
    //private Option<Boolean> ex = new Option<Boolean>("ex", "ex", true);
    private Numbers<Double> amount = new Numbers<Double>("amount", "amount", 30.0, 10.0, 100.0, 10.0);
    public Regen() {
        super("Regen", new String[] {"Regen"}, ModuleType.Misc);
        this.addValues(mode,amount);
    }
    @EventHandler
    private void onUpdate(EventPreUpdate event) {
       // Helper.sendMessage("WSSSSS");
        this.setSuffix(this.mode.getValue());
        if (mode.getValue()==RegMode.Potion) {
            if (mc.thePlayer.getActivePotionEffect(Potion.regeneration) != null && (mc.thePlayer.onGround || BlockUtils.isOnLadder() || BlockUtils.isInLiquid() || BlockUtils.isOnLiquid()) && mc.thePlayer.getHealth() < mc.thePlayer.getMaxHealth()) {
                for (int i = 0; i < mc.thePlayer.getMaxHealth() - mc.thePlayer.getHealth(); ++i) {
                    if (mc.thePlayer.getActivePotionEffect(Potion.regeneration) == null)
                        break;
                    mc.getNetHandler().addToSendQueue(new C03PacketPlayer(true));
                }
            }
        }

        if (mode.getValue()==RegMode.Old) {
            if (mc.thePlayer.getHealth() < mc.thePlayer.getMaxHealth() && mc.thePlayer.getFoodStats().getFoodLevel() > 0) {
                for (int i = 0; i < amount.getValue(); i++) {
                    mc.thePlayer.sendQueue.addToSendQueueNoEvent(new C03PacketPlayer(true));
                }
            }
        }
    }
    enum RegMode{
        Old,
        Potion;
    }

}
